<?php
header('Content-type:text/html;charset=utf-8;');

//包含数据库配置
include '../../public/peizhi.php';

//包含函数
include '../../public/func.php';

//调用函数
$link = db();

//接值表单
$uid = $_POST['uid'];

$qx = $_POST['qx'];

$email = $_POST['email'];

//接值文件
$_FILES;

//判断用户是否上传头像
if($_FILES['pic']['error'] != 4){
	//调用上传函数
	$uname =  upload('pic','../../uploads');
	//调用缩放函数
	$newpic = suofang('../../uploads/'.basename($uname),50,50,'../../uploads/');
	//删除缩放前的原图
	if(isset($newpic)){
		unlink('../../uploads/'.basename($uname));
	}
}else{
	$newpic = $_POST['oldpic'];
}

//判断用户是否选择性别
if(isset($_POST['sex'])){
	$sex = $_POST['sex'];
}else{
	exit('<script>alert("请选择性别");window.location.href="show.php";</script>');
}

//判断用户年龄
if($_POST['age'] < 150 && $_POST['age'] > 0){
	$age = $_POST['age'];
}else{
	exit('<script>alert("请输入正确年龄格式");window.location.href="show.php";</script>');
}

//判断用户邮箱
if(!empty($_POST['email'])){
	$email = $_POST['email'];
}else{
	exit('<script>alert("请填写邮箱");window.location.href="show.php";</script>');
}

//准备SQL语句
$sql = "update user set sex='{$sex}',age='{$age}',email='{$email}',pic='{$newpic}',qx='{$qx}' where id='{$uid}'";

//执行SQL语句
if($res = mysqli_query($link,$sql)){
	echo '<script>alert("修改用户成功");window.location.href="show.php";</script>';
}else{
	echo '<script>alert("修改用户失败");window.location.href="show.php";</script>';
}

//关闭数据库连接
mysqli_close($link);


